<?php

/*
 * Action - 5$
 *
 * Name a card. Reveal cards from the top of your deck
 * until you reveal 3 cards that are not the named card.
 * Put those cards into your hand and discard the rest.
 *
 */

class Journeyman extends Card implements iAction, iKingdom, iGuilds {

    public function __construct() {
        parent::__construct("Journeyman", 5);
        $this->undoPlay = false;
        $this->undoBuy = false;
    }
    
    public function getDisplayName($quantity = 1) {
        if ($quantity == 1) {
            return "Journeyman";
        }
        return $quantity . " Journeymen";
    }

    public function getDescription() {
        return array(
            "Name a card. Reveal cards from the top of your deck until you reveal 3 cards that are not the named card.",
            "Trash the maatches. Put the rest on top in any orderPut those cards into your hand and discard the rest.",
        );
    }

    public function play(Game $game, $isRealCard) {

        $board_cards = $game->getAllBoardCards();
        ksort($board_cards);
        
        $output = MySocket::GetUserReply($game, Input_ChooseOne, $board_cards, 1, 1, null, "Name a card");

        $named_card = n2c($output[0]);
        ScreenDisplay::addScreenMessage($game, true, "name " . nicePrint($named_card), "names " . ScreenDisplay::$LMSG);


        $i = 0;
        $discarded_cards = array();
        $drawed_cards = array();
        while ($i < 3) {
            $card = $game->peekCardFromDrawDeck();

            if (!$card)
                break;
            if ($named_card->getKey() != $card->getKey()) {
                $i+=1;
                $game->drawCards(1);
                $drawed_cards[] = $card;
            } else {
                $card = $game->removeCardFromDrawDeck();
                $discarded_cards[] = $card;
            }
        }
        $game->discardTempDiscardCards($discarded_cards);
        ScreenDisplay::addScreenMessage($game, true, "put " . nicePrint($drawed_cards) . " in hand, and discard " . nicePrint($discarded_cards), "puts " . nicePrint($drawed_cards) . " in hand, and discards " . nicePrint($discarded_cards));

        $game->cardActionFinished();
        return true;
    }

}

?>